﻿//字酷云

$(function(){
// 字酷类别选择实现
// 日期：2013-3-24
var ffamilyzky={
             'qtzk':{name:'其他字体'},
			 'fzzk':{name:'方正字库'},
			 'hyzk':{name:'汉仪字库'},
			 'jmzk':{name:'金梅字库'},
			 'zhzk':{name:'中华字库'},
			 'mnzk':{name:'迷你字库'}
			 
               };
var opts = { data:ffamilyzky,
            ajax: url+"/getff",
			select: '#zkyffamily',
			head: "选择字库"
		
                    };
var linkageSelzkyffamily = new LinkageSel(opts);
linkageSelzkyffamily.onChange(function() {
		var v = linkageSelzkyffamily.getSelectedArr();	
	if (v[1]!="")
		  {
		    font=v[1];
		  
		  
	       $.include(getBasePath()+pub+"/css/"+v[0]+"/"+v[1]+".css" );  
	
		   fontdir=v[0];
		   }
		   
						});
// 字酷类别选择实现-------------------------------------end

//公共档实现 pdoc
var pd={     
             
             'pdjgs':{name:'讲故事'},
			 'pdsxh':{name:'说笑话'},
			 'pdxsc':{name:'写诗词'},
			 'pdjmy':{name:'记名言'},
			 'pdxdl':{name:'写对联'},
			 'pdxyy':{name:'写谚语'},
			 'pdxsw':{name:'学中医'},
			 'pdxsw':{name:'写散文'}
			 
               };
var pdopt = { data:pd,
          //  ajax: url+"/getpd",
			select: '#pd',
			head: "公共目录"
                    };
var linkageSelpd = new LinkageSel(pdopt);
linkageSelpd.onChange(function() {
                tt=this.getSelectedValue();
		init_zt(tt,this.getSelectedData('name'),'tree1');
	
						});
//公共档实现 pdoc----------------------------end

//文档保存，新建，分享，删除 消息函数
//日期:2013-3-25 
$("#ggml").bind("click",function()
             {	
			 
              $.ajax({
			type:"POST",
			url:url+"/ggcontents",
		    data:{content:$("iframe").contents().find(".ke-content").html(),fd:filedir,dt:tt},
			dataType:"json",
			error:function (XMLHttpRequest, textStatus, errorThrown) {alert('请求错误...'+errorThrown);},
			success:function(data){
         		
			alert(data.data);
			location.reload();	 
				  
			        }
		              });
             
              });
//保存						
$("#bc").bind("click",function()
             {	
			
              $.ajax({
			type:"POST",
			url:url+"/getcontents",
		    data:{content:$("iframe").contents().find(".ke-content").html(),fd:filedir,dt:tt},
			dataType:"json",
			error:function (XMLHttpRequest, textStatus, errorThrown) {alert('请求错误...'+errorThrown);},
			success:function(data){
         		
			alert(data.data);
			location.reload();	 
				
			        }
		              });
              });
//新建
$("#xj").bind("click",function() {
 location.reload();
});
//分享
$("#fx").bind("click",function() { 
 window.open('http://app.t.qq.com/share/index?appid=100683506&msg=字酷云，我的字体，我做主',"_blank");
   location.reload();
});
//删除
 $("#xc").bind("click",function() {
        $.ajax({
			 type:"POST",
			 url:url+"/delcontents",
		     data:{file:filedir},
			 dataType:"json",
			 error:function (XMLHttpRequest, textStatus, errorThrown) {alert('请求错误...'+errorThrown);},
			 success:function(data){
         	   alert(data.data);
				location.reload();	   
			        }
		              });

         });  
		 
		 
//获取根目录\
//日期：2013-03-24				
function getBasePath() {
        var curWwwPath = window.document.location.href;
        var pathName = window.document.location.pathname;
        var pos = curWwwPath.indexOf(pathName);
         var localhostPaht = curWwwPath.substring(0, pos);
       
      return localhostPaht;
 }
//获取根目录 -----------------------------end
	
// 插入字酷css文件 函数jquery 实现
$.extend({  
    includePath: '',  
    include: function(file)  
    {  
        var files = typeof file == "string" ? [file] : file;  
        for (var i = 0; i < files.length; i++)  
        {  
            var name = files[i].replace(/^\s|\s$/g, "");  
            var att = name.split('.');  
            var ext = att[att.length - 1].toLowerCase();  
            var isCSS = ext == "css";  
            var tag = isCSS ? "link" : "script";  
            var attr = isCSS ? " type='text/css' rel='stylesheet' " : " type='text/javascript' ";  
            var link = (isCSS ? "href" : "src") + "='" + $.includePath + name + "'";  
            if ( $("iframe").contents().find(tag + "[" + link + "]").length == 0)  $("iframe").contents().find(".ke-content").append("<" + tag + attr + link + "></" + tag + ">");  
        }  
    }  
});  
init_zt('kwd','酷文档','tree');
// 插入字酷css文件 函数jquery 实现	 -------end
//左侧目录树的初始化
function init_zt(dt,dtname,id)
{
     
var zTree;
var zNodes ;  
var setting = {
		view: {
			dblClickExpand: false,
			showLine: true,
			selectedMulti: false,
			expandSpeed: ($.browser.msie && parseInt($.browser.version)<=6)?"":"fast"
		},
		data: {
			simpleData: {
				enable:true,
				idKey: "id",
				pIdKey: "pId",
				rootPId: ""
			}
		},
		callback: {
		 
			beforeClick: function(treeId, treeNode) {
				var zTree = $.fn.zTree.getZTreeObj("tree");
				if (treeNode.isParent) {
					zTree.expandNode(treeNode);
					return false;
				} else {
				    
				  
				   filedir= treeNode.file; 
                    if(treeId=="tree")
                       {
                    	
						$("#topmenu").css("display","block");
						$("#zt").css("display","block"); 
						$("#zt1").css("display","none"); 
					  $.ajax({
		                 async : false,
                         cache : false,
			             type:"POST",
			             url:url+"/getcon",
		                data:{fp:treeNode.file},
			            dataType:"json",
			            error:function (XMLHttpRequest, textStatus, errorThrown) {alert('请求错误...'+errorThrown);},
			            success:function(data){
						
			               $("iframe").contents().find(".ke-content").empty();
			              $("iframe").contents().find(".ke-content").append(data.data);
			                                   }
		              });
			        } else{
					$("#topmenu").css("display","none");
					$("#zt").css("display","none");
					$("#zt1").css("display","block");
					//$("#zt1").empty();
					//$("#zt1").append("<iframe id='zky-tta1' style='width:99%;height:960px;'></iframe>");
					//$("#zky-tta1").attr("src",treeNode.file);
					$("#zt1").find(".ke-edit-iframe").attr("src",treeNode.file);
					}
					return true;
				}
			}
		}
	};
	

	 $.ajax({
		async : false,
        cache : false,
			type:"POST",
			url:url+"/getzon",
		    data:{dt:dt,dtname:dtname},
			dataType:"json",
			error:function (XMLHttpRequest, textStatus, errorThrown) {alert('请求错误...'+errorThrown);},
			success:function(data){
				zNodes=eval(data.data); 
			
			        }
		              });
	 $.fn.zTree.init($("#"+id), setting, zNodes);

       
}
       
//左侧目录树的初始化------------------------end


});

// 主编辑区定义字库云插件并实例化 
			KindEditor.lang({
				fontface: '字酷云'
			});
			KindEditor.plugin('fontface', function(K) {
				var self = this, name = 'fontface';			
				self.clickToolbar(name, function() {
				$.ligerDialog.open({ isHidden: true, top:25,left:100, target: $("#zkyffamilyd") ,
				         buttons: [ { text: '确定', 
				             onclick: function (item, dialog)
							 {
							 self.exec('fontname', font);
							// self.cmd.wrap("<span style='font-family: "+ font + ";'></span>");	 
				    // self.cmd.select();
					 dialog.hidden();
					 }
					 }, 
					 { text: '取消', 
					 onclick: function (item, dialog)
					 { dialog.hidden(); } } ]
					 });
				
				});
			});
			KindEditor.ready(function(K) {
				editor=	KindEditor.create('#zky-tta', {
					resizeType : 1,
					allowPreviewEmoticons : false,
					allowImageUpload : false,
					items : [
						'fontface', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
						'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
						'insertunorderedlist', '|', 'emoticons', 'image', 'link','source']
					
				});
				
			});
			
			KindEditor.ready(function(K) {
				editor=	KindEditor.create('#zky-tta1', {
					resizeType : 1,
					allowPreviewEmoticons : false,
					allowImageUpload : false,
					items : ['fullscreen','print'
						]
					
				});
				
			});

// 主编辑区定义字库云插件并实例化 ------end	

// 布局和菜单实现


        
$(function ()
                {

                    $("#layout1").ligerLayout({height:'90%',leftWidth: 200});
			        $("#topmenu").ligerMenuBar({ items: [
                { text: '字体下单', click:itemclickztxd },
				{ text: '我的订单', click:itemclickwddd },
				{ text: '生成作品', click:itemclicksczp },
				{ text: '我的作品', click:itemclickwdzp },
                { text: '作品展示',click:itemclickzpzs }
                  ]});
			$("#maingrid").ligerGrid({
                columns: [
                { display: '订单编号', name: 'CustomerID', align: 'left', width: 100, minWidth: 60 },
                { display: '图片路径', name: 'CompanyName', minWidth: 120 },
                { display: '下单时间', name: 'ContactName', minWidth: 140 },
                { display: '订单状态', name: 'City' }
                ], data:CustomersData, sortName: 'CustomerID',height:300,pageSize:30 
            });

                });
		function itemclickztxd()
{

}	
		function itemclickwddd()
{

}	
		function itemclicksczp()
{

}	
		function itemclickwdzp()
{

}	
		function itemclickzpzs()
{

}		
   
        function itemclickggml(item)
        {     
		      $.ligerDialog.open({ isHidden: true, top:25,left:100, target: $("#pdd") ,
				         buttons: [ { text: '确定', 
				             onclick: function (item, dialog)
							 {
						
					 dialog.hidden();
					 
              $.ajax({
			type:"POST",
			url:url+"/ggcontents",
		    data:{ fd:filedir,dt:tt},
			dataType:"json",
			error:function (XMLHttpRequest, textStatus, errorThrown) {alert('请求错误...'+errorThrown);},
			success:function(data){
         		
			 alert(data.data);
			 location.reload();	 
				  
			        }
		              });
					 }
					 }, 
					 { text: '取消', 
					 onclick: function (item, dialog)
					 { 
					 dialog.hidden();} } ]
					 });
				
            
             
        }
		function itemclickxsggml(item)
        {     
		      $.ligerDialog.open({ isHidden: true, top:25,left:100, target: $("#pdd") ,
				         buttons: [ { text: '确定', 
				             onclick: function (item, dialog)
							 { dialog.hidden();			        }
		             
					 }]
					 });
				
            
             
        }
		function itemclickxj(item)
        {
             location.reload();
        }
    function itemclickbc(item)
        {
                           $.ajax({
			type:"POST",
			url:url+"/getcontents",
		    data:{content:$("iframe").contents().find(".ke-content").html(),fd:filedir,dt:tt},
			dataType:"json",
			error:function (XMLHttpRequest, textStatus, errorThrown) {alert('请求错误...'+errorThrown);},
			success:function(data){
         		
			alert(data.data);
			location.reload();	 
				
			        }
		              });

        } 
   function itemclickxc(item)
        {
             $.ajax({
			 type:"POST",
			 url:url+"/delcontents",
		     data:{file:filedir},
			 dataType:"json",
			 error:function (XMLHttpRequest, textStatus, errorThrown) {alert('请求错误...'+errorThrown);},
			 success:function(data){
         	   alert(data.data);
				location.reload();	   
			        }
		              });
        } 
function itemclickfx(item)
        {
            window.open('http://app.t.qq.com/share/index?appid=100683506&msg=字酷云，我的字体，我做主',"_blank");
   location.reload();
        } 
	